package com.cxh.rmsq.utils.dialog

import android.content.Context
import android.text.Editable
import android.text.TextUtils
import android.text.TextWatcher
import android.widget.CheckBox
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import androidx.lifecycle.ViewModelProvider
import com.blankj.utilcode.util.SPUtils
import com.blankj.utilcode.util.ToastUtils
import com.cxh.rmsq.R
import com.cxh.rmsq.net.newNet.TreasureViewModel
import com.cxh.rmsq.utils.MyUtils
import com.cxh.rmsq.utils.TextSpanUtil
import com.hjq.shape.view.ShapeEditText
import com.hjq.shape.view.ShapeTextView
import com.lxj.xpopup.core.BottomPopupView
import com.lxj.xpopup.core.CenterPopupView
import com.lxj.xpopup.util.XPopupUtils
import com.xuexiang.xui.utils.XToastUtils
import kotlin.math.roundToInt


class PayQrcodePopup(
    context: Context,
    type: Int,
    content: String,
    click: onClick
) :
    CenterPopupView(context) {
    private val viewModel by lazy {
        ViewModelProvider.NewInstanceFactory().create(TreasureViewModel::class.java)
    }
    interface onClick {
        fun click(content: String, s1: Int)
    }

    var func: onClick
    var type: Int
    var content: String
    var s1: Int = 1

    init {
        this.func = click
        this.content = content
        this.type = type
    }

    override fun getImplLayoutId(): Int {
        return R.layout.pay_qrcode_popup
    }

    override fun onCreate() {
        super.onCreate()

        var iv_del = findViewById<ImageView>(R.id.iv_del)
        var iv_qrcode = findViewById<ImageView>(R.id.iv_qrcode)
        var tv_tips = findViewById<TextView>(R.id.tv_tips)
        iv_qrcode.setImageBitmap(MyUtils.generateQRCode(content, 800))
        if (type ==4){
            tv_tips.text = "二维码有效期10分钟\n请使用微信尽快扫码付款"
        }else {
            tv_tips.text = "二维码有效期10分钟\n请使用支付宝尽快扫码付款"
        }
        iv_del.setOnClickListener {
//            viewModel.deleteTreasureOrder(SPUtils.getInstance().getString("orderId")) {
//                if (it.code == 200) {
//                    dismiss()
//                } else {
//                    com.cxh.rmsq.utils.ToastUtils.showToast(it.msg)
//                }
//            }
            com.cxh.rmsq.utils.ToastUtils.showToast("购买完成后请手动下拉刷新会员状态")
            func.click(
                "",
                s1,
            )
            dismiss()
        }

    }

    // 最大高度为Window的0.85
    override fun getMaxHeight(): Int {
        return ((XPopupUtils.getAppHeight(context) * .55f).roundToInt())
    }

}